﻿using AutoMapper;
using System.Collections.Generic;

namespace JoceLinItemDemo.API.AutoMapper
{
    public class MapperHelp
    {
        public IMapper Build()
        {
            var configuration = new MapperConfiguration(option =>
            {
                // 每进行两个类之间的转化，都需要创建一下
                // option.CreateMap<nc_greenvote_config, MainSetInfoDto>().ReverseMap();
            });
            //configuration.AssertConfigurationIsValid();
            var mapper = configuration.CreateMapper();

            return mapper;
        }

        // AutoMapper使用案例
        public class LoginUserInfo
        {
            public int Id { get; set; }
            public string UserName { get; set; }
            public string Password { get; set; }
            public string Email { get; set; }
            public string Phone { get; set; }
            public string PhoneNumber { get; set; }
            public string Address { get; set; }
        }
        public class LoginUserInfoDto 
        {
            public int Id { get; set; }
            public string UserName { get; set; }
            // public string Password { get; set; }
            public string Email { get; set; }
            public string Phone { get; set; }
            public string PhoneNumber { get; set; }
            public string Address { get; set; } 
        }
        public List<LoginUserInfoDto> CaseInfo()
        {
            List<LoginUserInfo> loginUserInfos = new List<LoginUserInfo>
            {
                new LoginUserInfo{Id=1,UserName="zhangsan",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
                new LoginUserInfo{Id=2,UserName="lisi",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
                new LoginUserInfo{Id=3,UserName="wangwu",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
                new LoginUserInfo{Id=4,UserName="zhaoliu",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
                new LoginUserInfo{Id=5,UserName="xueqi",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"}, 
                new LoginUserInfo{Id=6,UserName="chenba",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
                new LoginUserInfo{Id=7,UserName="wujiu",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
                new LoginUserInfo{Id=8,UserName="hanshis",Password="123456",Email="123456@qq.com",Phone="12345678910",PhoneNumber="1",Address="1"},
            };

            MapperHelp help = new MapperHelp();
            IMapper _mapper = help.Build();

            // 传输需要的对象
            List<LoginUserInfoDto> loginUserInfoDto = _mapper.Map<List<LoginUserInfoDto>>(loginUserInfos);

            return loginUserInfoDto;
        }
    } 
}
